package vn.appsmobi.widget;

import vn.appsmobi.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.ImageSwitcher;
import android.widget.LinearLayout;

public class ImageGalleryView extends HorizontalScrollView {

	LinearLayout mGalleryOuter;
	Context mContext;
	public ImageGalleryView(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater.from(context).inflate(R.layout.image_gallery, this, true);
		this.mGalleryOuter = ((LinearLayout)findViewById(R.id.gallery_outer));
		this.mContext = context;
		//this.mGalleryOuter.on
	}

	/**Phong
	 * @param context
	 */
	public ImageGalleryView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	

	
	
	public View getScreen(int position)
	{
		View v = null;
		if(position < 0 || position > getScreenCount())
			return v;		
		 v = this.mGalleryOuter.getChildAt(position);
		 return v;
	}
	
	public int getScreenCount()
	{
		return this.mGalleryOuter.getChildCount();
	}
	
	

	public void addImage(ImageSwitcher imgSwitcher) {
		// TODO Auto-generated method stub
		
		this.mGalleryOuter.addView(imgSwitcher);
	}
	
	
	/*
	@Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
		
		 int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
		    int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
		    this.setMeasuredDimension(
		            parentWidth / 2, parentHeight);
		    
		    int mNoOfItems =  this.mGalleryOuter.getChildCount();

		    
	        for(int i = 0; i < mNoOfItems; i++)
	        {
	            View child = (View) this.mGalleryOuter.getChildAt(i);
	            ViewGroup.LayoutParams newLayout = new LinearLayout.LayoutParams(200 ,parentHeight);
	            child.setLayoutParams(newLayout);
	        }
		    
		    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		    final double viewWidthToBitmapWidthRatio = (double)image.getWidth() / (double)bitmap.getWidth();
		    
         Drawable d = getDrawable();

         if(d!=null){
                 // ceil not round - avoid thin vertical gaps along the left/right edges
                 int width = MeasureSpec.getSize(widthMeasureSpec);
                 int height = (int) Math.ceil((float) width * (float) d.getIntrinsicHeight() / (float) d.getIntrinsicWidth());
                 setMeasuredDimension(width, height);
         }else{
                 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
         }
         
    }
	
	
	@Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) 
    {
        super.onLayout(changed, left, top, right, bottom);
        int mNoOfItems =  this.mGalleryOuter.getChildCount();

        int itemLayoutWidth = getMeasuredWidth();
        for(int i = 0; i < mNoOfItems; i++)
        {
            View child = (View) this.mGalleryOuter.getChildAt(i);
            ViewGroup.LayoutParams newLayout = new LinearLayout.LayoutParams(200 ,300);
          //  child.setLayoutParams(newLayout);
        }
    }*/
	
}
